package com.example.controller.configuration;

import com.example.bean.configuration.PingGuMoBan;
import com.example.bean.configuration.PingGuXiangGuanLi;
import com.example.bean.configuration.vo.PingGuXiangGuanLiVo;
import com.example.service.configuration.PingGuXiangGuanLiService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/pingguxiangguanli")
public class PingGuXiangGuanLiController {
    @Autowired
    PingGuXiangGuanLiService service;

    @PostMapping("/page")
    public PageInfo<PingGuXiangGuanLi> page(@RequestBody PingGuXiangGuanLiVo vo){
        System.out.println(vo);
        return service.getpage(vo);
    }

    @PostMapping("/addpingguxiangguanli")
    public Result addpingguxiangguanli(@RequestBody PingGuXiangGuanLi pingGuXiangGuanLi){
        System.out.println(pingGuXiangGuanLi);
        Integer flag = service.addpingguxiangguanli(pingGuXiangGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/{aid}")
    public Result getById(@PathVariable String aid){
        PingGuXiangGuanLi pingGuXiangGuanLi = service.getId(aid);
        Result result = new Result();
        if(pingGuXiangGuanLi != null){
            result.ok();
            result.setData(pingGuXiangGuanLi);
        }else {
            result.fail("失败");
        }
        return result;
    }

    @PutMapping("/updatepgxgl")
    public Result update(@RequestBody PingGuXiangGuanLi pingGuXiangGuanLi){
        Integer flag = service.xiugai(pingGuXiangGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/qidong/{noid}")
    public Result qidong(@PathVariable String noid){
        Integer flag = service.qidong(noid);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/jinyong/{noid}")
    public Result jinyong(@PathVariable String noid){
        Integer flag = service.jinyong(noid);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }

    //批量删除
    @PostMapping("/dels")
    public Result dels(@RequestBody List<String> ids){
        //删除
        Integer flag = service.dels(ids);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }
}
